
package Type_1_arr.title4_P209;


//209. 长度最小的子数组
public class P209MiniMumSize1 {


    // TODO {2, 3, 1, 2, 4, 3}   暴力写法 超时了
    public static int minSubArrayLen(int[] nums, int target) {

        int resultMin = Integer.MAX_VALUE;  //TODO 默认取最大值


        int tempMinSum;    //最小数组和
        int tempMin;       //最新数组长度
        for (int i = 0; i < nums.length; i++) {

            tempMinSum = 0;//归0

            for (int j = i; j < nums.length; j++) {
                tempMinSum += nums[j];
                if (tempMinSum >= target) {  //满足条件
                    tempMin = j - i + 1;   //更新最小值
                    System.out.println("存在的可能：" + i + "-" + tempMin);
                    resultMin = Math.min(tempMin, resultMin);  //取小的那个

                    break;   //后面不用比较了
                }
            }
        }

        return resultMin == Integer.MAX_VALUE ? 0 : resultMin;

    }

    public static void main(String[] args) {

        int[] nums = {2, 3, 1, 2, 4, 3};
        int target = 7;

        int min = minSubArrayLen(nums, target);
        System.out.println("min:" + min);
    }
}